package com.pearson.lagp.v3;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.menu.MenuScene;
import org.anddev.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
import org.anddev.andengine.entity.scene.menu.item.IMenuItem;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import android.content.Intent;
import android.net.MailTo;
import android.os.Handler;

public class StartActivity extends BaseGameActivity {
    
	private final static int CAMERA_WIDTH = 480;
	private final static int CAMERA_HEIGHT = 320;
	
	private Camera mCamera;
	private BitmapTextureAtlas mTexture;
	private TextureRegion mSplashTextureRegion;
	private Handler mHandler;
	
	@Override
	public Engine onLoadEngine() {
		mHandler = new Handler();
		this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); 
		return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH,CAMERA_HEIGHT),this.mCamera));
	}
	
	@Override 
	public void onLoadResources() 
	{ 
		this.mTexture = new BitmapTextureAtlas(512, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA); 
		this.mSplashTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTexture, this, "gfx/Splashscreen.png", 0, 0); 
		this.mEngine.getTextureManager().loadTexture(this.mTexture);
	}
	
	@Override 
	public Scene onLoadScene() { 
		this.mEngine.registerUpdateHandler(new FPSLogger()); 
		final Scene scene = new Scene(); /* Center the splash on the camera. */ 
		final int centerX = (CAMERA_WIDTH - this.mSplashTextureRegion.getWidth()) / 2; 
		final int centerY = (CAMERA_HEIGHT -this.mSplashTextureRegion.getHeight()) / 2; /* Create the sprite and add it to the scene. */ 
		final Sprite splash = new Sprite(centerX, centerY, this.mSplashTextureRegion); 
		scene.attachChild(splash); 
		return scene;
	}
	
	@Override
	public void onLoadComplete() {
		mHandler.postDelayed(mLaunchTask, 3000);
	}
	
	private Runnable mLaunchTask = new Runnable()
	{
		public void run()
		{
			Intent myIntent = new Intent(StartActivity.this, MainMenuActivity.class);
			StartActivity.this.startActivity(myIntent);
		}
	};
}